package com.usian.listener;

import com.usian.controller.CartController;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

@Component
public class CartMQListener {
    @Autowired
    private CartController cartController;
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value="search_queue",durable = "true"),
            exchange = @Exchange(value="gouwuche",type= ExchangeTypes.TOPIC),
            key= {"gouwuche.*"}
    ))
    public void listen(String msg,HttpServletRequest request) throws Exception {
        System.out.println("接收到消息：" + msg);

        Boolean result = cartController.gouwuchetongbu(request,msg);
        if(!result){
            throw new RuntimeException("同步失败");
        }
    }

}
